package com.chengqs.jvm.t3.jit;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class JIT3 {
    int[] elements = randomInts(1_000);

    public static void main(String[] args) {

    }

    private static int[] randomInts(int size) {
        Random random = ThreadLocalRandom.current();
        int[] values = new int[size];
        for (int i = 0; i < size; i++) {
            values[i] = random.nextInt();
        }
        return values;
    }

    public void test2() {
        int[] local = this.elements;
        for (int i = 0; i < local.length; i++) {
            doSum(local[i]);
        }
    }

    public void test3() {
        for (int element : elements) {
            doSum(element);
        }
    }

    static int sum = 0;

    static void doSum(int x) {
        sum += x;
    }
}
